const Service = require('egg').Service;

class ProductService extends Service {
  async login(password,phone) {
    try{
        const res = await this.app.mysql.select('userlist', {
            where: { phone: phone, password: password }
        })
        if (res.length > 0) {
            return {
                code: 1,
                msg: "登录成功",
                username:res[0].username,
                //生成token
                token: this.app.jwt.sign({ username: res[0].username },
                    this.app.config.jwt.secret,
                    { expiresIn: 60 * 60 * 24 })
            }
        } else {
            return {
                code: 0,
                msg: "登录失败"
            }
        }
    }catch(e){
        return {
            code:0,
            msg:e.message
        }
    }
  }
}

module.exports = ProductService;
